package com.longdaji.decoration.ui.activitiesOfMine.feedback;

import com.longdaji.decoration.base.RxPresenter;
import com.longdaji.decoration.bean.Account;
import com.longdaji.decoration.data.DataManager;
import com.longdaji.decoration.data.network.CommonSubscriber;
import com.longdaji.decoration.data.network.HttpResponse;
import com.longdaji.decoration.utils.LogUtil;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Kanade on 2018/5/2 0002.
 */

public class DoFeedbackPresenter extends RxPresenter<DoFeedbackContract.IView> implements DoFeedbackContract.IPresenter {
    private DataManager mDataManager;

    private static final String TAG = "DoFeedbackPresenter";

    @Inject
    public DoFeedbackPresenter(DataManager dataManager) {
        this.mDataManager = dataManager;
    }

    @Override
    public void doFeedback(String content, String connection) {
        addSubscribe(mDataManager.doFeedbackApi(Account.getInstance().getUserid(), connection, content)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new CommonSubscriber<HttpResponse>() {
                    @Override
                    public void onSuccess(HttpResponse httpResponse) {
                        LogUtil.d(TAG, "success  doFeedbackApi");
                        mView.showDoFeedbackSuccess();
                    }

                    @Override
                    public void onFailed(String msg) {
                        LogUtil.d(TAG, "fail  doFeedbackApi: " + msg);

                    }
                }));
    }
}
